package com.stylefeng.guns.modular.processmanager.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.util.ToolUtil;

import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ActProcessType;
import com.stylefeng.guns.modular.processmanager.service.IActProcessTypeService;

/**
 * 流程分类控制器
 *
 * @author fengshuonan
 * @Date 2019-01-15 21:54:20
 */
@Controller
@RequestMapping("/actProcessType")
public class ActProcessTypeController extends BaseController {

    private String PREFIX = "/processmanager/actProcessType/";

    @Autowired
    private IActProcessTypeService actProcessTypeService;

    /**
     * 跳转到流程分类首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "actProcessType.html";
    }

    /**
     * 跳转到添加流程分类
     */
    @RequestMapping("/actProcessType_add")
    public String actProcessTypeAdd() {
        return PREFIX + "actProcessType_add.html";
    }

    /**
     * 跳转到修改流程分类
     */
    @RequestMapping("/actProcessType_update/{actProcessTypeId}")
    public String actProcessTypeUpdate(@PathVariable Integer actProcessTypeId, Model model) {
        ActProcessType actProcessType = actProcessTypeService.selectById(actProcessTypeId);
        model.addAttribute("item",actProcessType);
        LogObjectHolder.me().set(actProcessType);
        return PREFIX + "actProcessType_edit.html";
    }

    /**
     * 获取流程分类列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	//条件为空查询所有
    	if (ToolUtil.isEmpty(condition)) {
    		 return actProcessTypeService.selectList(null);
    	}
    	//条件不为空则模糊查询
    	
    	EntityWrapper<ActProcessType> actProcessType = new EntityWrapper<>();
    	Wrapper<ActProcessType> wrapper = actProcessType.like("name_", condition);
    	
    	
        return actProcessTypeService.selectList(wrapper);
    }

    /**
     * 新增流程分类
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ActProcessType actProcessType) {
        actProcessTypeService.insert(actProcessType);
        return SUCCESS_TIP;
    }

    /**
     * 删除流程分类
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer actProcessTypeId) {
        actProcessTypeService.deleteById(actProcessTypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改流程分类
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ActProcessType actProcessType) {
        actProcessTypeService.updateById(actProcessType);
        return SUCCESS_TIP;
    }

    /**
     * 流程分类详情
     */
    @RequestMapping(value = "/detail/{actProcessTypeId}")
    @ResponseBody
    public Object detail(@PathVariable("actProcessTypeId") Integer actProcessTypeId) {
        return actProcessTypeService.selectById(actProcessTypeId);
    }
}
